/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */
import { describe, expect, test } from '@jest/globals';

import { CompileModeEnum } from '../../../src/enum/compile-mode-enum';
import { initByStageEmptyApp, initExecuteCommand, runHvigor } from '../common/common';
import { ModuleBuildProfileModifier } from '../common/modifier/module-build-profile-modifier';

describe('hot reload assemble hap', () => {
  test.concurrent('stage esmodule app', async () => {
    await initByStageEmptyApp(async (dir) => {
      const entryBuildProfile = new ModuleBuildProfileModifier(dir, 'entry');
      entryBuildProfile.setCompileMode(CompileModeEnum.ES_MODULE)
        .outputSync();

      const commands = initExecuteCommand({
        mode: 'module',
        product: 'default',
        module: 'entry',
        tasks: 'assembleHap',
        hotReload: true
      });
      try {
        runHvigor(dir, commands, { stderr: 'pipe' });
      } catch (e: any) {
        // 直接打包报错, 该任务无法在没有执行前置后执行
        expect(e.stderr).toContain(':entry:default@PackageHap');
      }
    });
  });
});
